package org.jasig.cas.client.configuration;

import java.util.Timer;

import javax.servlet.Filter;
import javax.servlet.FilterConfig;

import org.jasig.cas.client.util.CommonUtils;

import net.zoneland.cas.CasAppHelper;
import net.zoneland.cas.spi.impl.CasConfigProvider4client;

public class CustomConfigurationStrategy extends BaseConfigurationStrategy {

    private final WebXmlConfigurationStrategyImpl webXmlConfigurationStrategy = new WebXmlConfigurationStrategyImpl();

    public CustomConfigurationStrategy() {
        super();
        if (initGlobalOn == null) {
            initGlobal();
        }
    }

    public void init(FilterConfig filterConfig, Class<? extends Filter> filterClazz) {
        this.webXmlConfigurationStrategy.init(filterConfig, filterClazz);
    }

    protected String get(final ConfigurationKey key) {
        final String k = "cas."+key.getName();
        final String value1 = CasAppHelper.getProperty(k, null);
        if (CommonUtils.isNotBlank(value1)) {
            return value1;
        }
        return this.webXmlConfigurationStrategy.get(key);
    }
    
    private static Boolean initGlobalOn;
    
    public static boolean isInitGlobalOn() {
        return initGlobalOn == null ? false : initGlobalOn;
    }
    public static void initGlobal() {
        CasConfigProvider4client.setTimer(new Timer());
        initGlobalOn = true;
    }
}
